package cn.com.yusys.yusp.admin.service;

import cn.com.yusys.yusp.admin.domain.AdminSmProp;
import cn.com.yusys.yusp.admin.repository.mapper.AdminSmPropMapper;
import cn.com.yusys.yusp.admin.service.impl.PropProviderServiceImpl;
import cn.com.yusys.yusp.commons.mapper.CommonMapper;
import cn.com.yusys.yusp.commons.mapper.QueryModel;
import cn.com.yusys.yusp.commons.service.CommonService;
import cn.com.yusys.yusp.commons.util.DateUtil;

import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;


/**
 * @项目名称：yusp-admin
 * @类名称：AdminSmPropService
 * @类描述：系统参数
 * @功能描述:
 * @创建人：liaoxd@yusys.com.cn
 * @创建时间：2017-12-16 15:05
 * @修改备注：
 * @修改日期		修改人员		修改原因
 * --------    --------		----------------------------------------
 * @version 1.0.0
 * @Copyright (c) 2017宇信科技-版权所有
 */
@Service
public class AdminSmPropService extends CommonService {
	@Autowired
	private AdminSmPropMapper mapper;

	@Autowired
	private PropProviderServiceImpl propCache;
	
	@Override
	protected CommonMapper<?> getMapper() {
		return this.mapper;
	}

	@Override
	public int insert(Object record) {
		AdminSmProp adminSmProp = (AdminSmProp)record;
		adminSmProp.setLastChgDt(DateUtil.formatDateTimeByDef());
		int n= this.insert(getMapper(), record);
		if(n>0) {
			//先删除缓存在刷新缓存
	        //stringRedisTemplate.delete("propInfo::findAllProp");
			propCache.cleanAllProp();
	        propCache.findAllProp();
		}
		return n;
	}

	@Override
	public int updateSelective(Object record) {
		AdminSmProp adminSmProp = (AdminSmProp)record;
		adminSmProp.setLastChgDt(DateUtil.formatDateTimeByDef());
		int n=this.updateSelective(getMapper(), record);
		if(n>0) {
			//先删除缓存在刷新缓存
	        //stringRedisTemplate.delete("propInfo::findAllProp");
			propCache.cleanAllProp();
	        propCache.findAllProp();
			
		}
		return n;
	}
	
	
	/**
     * @函数名称:selectByModel
     * @函数描述:重新，支持页面模糊查询
     * @参数与返回说明:
     * @算法描述:
     */
    @Override
    @SuppressWarnings("unchecked")
	public <T> List<T> selectByModel(QueryModel model) {
//		if(model.getCondition().containsKey("propName")) {
//			model.getCondition().put("propName","%"+ model.getCondition().get("propName")+"%");
//		}
//		if(model.getCondition().containsKey("propDesc")) {
//			model.getCondition().put("propDesc","%"+ model.getCondition().get("propDesc")+"%");
//		}
//		
		// 设置分页查询参数(设置到线程变量中了)
		PageHelper.startPage(model.getPage(), model.getSize());
		List<Map<String,String>> list=this.mapper.getPropListBycodeOrName( model);
		// 清除线程绑定的分页参数，防止影响同线程的其他查询
		PageHelper.clearPage();
		return (List<T>) list;
	}
}